package com.lms.generictype.demo2;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-01-16 16:45
 * @Description: 类型通配符 上下限
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("下限测试");
        Box<Integer> box = new Box<>();
        box.setNum(50);
        showBox(box);
        showBox2(box);
        Box<Number> box1 = new Box<>();
        box1.setNum(30);
        showBox(box1);
        showBox2(box1);
        System.out.println("上限测试");
        Fruit<Integer> fruit = new Fruit<>();
        fruit.setNum(20);
        showFruit(fruit);
        Fruit<Number> fruit2 = new Fruit<>();
        fruit2.setNum(52);
        showFruit(fruit2);

    }
    public static void showBox(Box<? extends Number> box) {
        System.out.println(box.getNum());

    }
    public static<E extends Number> void showBox2(Box<E> box) {
        System.out.println(box.getNum());

    }
    public static void showFruit(Fruit<? super Integer> fruit){
        System.out.println(fruit.getNum());

    }
}
